import store from '@/store';
import {
  getLogoBase64String
} from '@/apis/file';
import {
  getAppTitle,
  getAppDescription
} from '@/apis/system/admin/settings';

/**
 * 应用设置
 * @param app 应用对象
 */
export async function appSetup() {
  //#region 系统logo处理
  const logo = await getLogoBase64String();
  if (logo) {
    await store.dispatch('setLogo', logo);
  }
  //#endregion

  //#region 系统标题处理
  const appTitle = await getAppTitle();
  if (appTitle) {
    await store.dispatch('setAppTitle', appTitle);
  }
  //#endregion

  //#region 系统描述处理
  const appDescription = await getAppDescription();
  if (appDescription) {
    if (appDescription.Description) {
      await store.dispatch('setAppDescription', appDescription.Description);
    }
    if (appDescription.Subdescription) {
      await store.dispatch('setAppSubdescription', appDescription.Subdescription);
    }
  }
  //#endregion

  // 监测打印机状态
  await store.dispatch("viaPrinterBleState");

  // 设置主题
  // getCurrentTheme();

  // 设置心跳，用于刷新Token
  // if(store.getters.hasLogin){
  // 	await store.dispatch("viaHeartbeats");
  // }
  await store.dispatch("viaHeartbeats");

}